package jalus.tools;

import jalus.utils.CaptchaUtils;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@SuppressWarnings("serial")
public class CaptchaServlet extends HttpServlet{

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)	throws IOException {
		
		HttpSession session = req.getSession();
		resp.setContentType("image/gif");
		OutputStream out = resp.getOutputStream();
		String code = (String)session.getAttribute("code");
		if(code != null){
			CaptchaUtils.generate(code, out);
		}else{
			resp.setStatus(404);
		}
	}
}
